<?php

/*
Class name: DBClass
Author: Ali GOREN
Version: 1.0
PHP Version: 5.3.X =>
*/


class Database {

	private $db_host = "localhost"; // host variable
	private $db_user = "example"; // database user
	private $db_password = "example"; // database password
	private $db_database = "example"; // database name
	
	private $db_connection; // database connection variable
	
	function __construct()
	{
		
		if($this->db_connect())
		{
			
			if($this->db_select())
			{
			
				echo 'CONGRATULATIONS: Database connection established.'; // connecti
			
			} else {
			
				echo 'ERROR: The database could not be selected.'; // error: not selected
				exit();
			
			}
		} else {
		
			echo 'ERROR: Failed to connect to the database.'; // connection error
			exit();
		
		}
		
	}
	
	private function db_connect()
	{
	
		$this->db_connection = @mysql_connect($this->db_host, $this->db_user, $this->db_password); // mysql connection
		
		if($this->db_connection)
		{
		
			return true; // db connect congrulations ? true
			
		} else {
		
			return false; // db not connect ? false
			
		}
	
	}
	
	private function db_select()
	{
	
		$db_var = mysql_select_db($this->db_database, $this->db_connection); // database selected
		
		if($db_var)
		{
		
			return true; // db selected congrulations ? true
			
		} else {
		
			return false; // db not selected ? false
			
		}
	}
	
	private function db_close()
	{
		$this->db_connection = @mysql_close($this->db_connection); // db close
		
		if($this->db_connection)
		{
		
			return true; // db closed congrulations ? true
			
		} else {
		
			return false; // db not closed ? false
			
		}
		
	}
	
	function __destruct()
	{
	
		$this->db_close(); // db close
		
	}

}


// example;

$database = new Database(); // db class :-)

?>